package com.gibs.peixunapi.dao;

import java.util.List;

import com.gibs.peixunapi.model.TestPaper;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.gibs.peixunapi.model.ExamInfo;

@Repository
public interface ExamInfoDao extends JpaRepository<ExamInfo, Integer>, JpaSpecificationExecutor<ExamInfo> {

	@Query("from ExamInfo where name = ?1")
	List<ExamInfo> find(String name);

	@Query("from ExamInfo where name like ?1")
	List<ExamInfo> findLike(String name);

	@Query(value = "select * from ExamInfo limit ?, ?", nativeQuery = true)
	List<ExamInfo> findPage(Integer offset, Integer size);

	@Query(value = "select * from ExamInfo where name = ? limit ?, ?", nativeQuery = true)
	List<ExamInfo> findPage(String name, Integer offset, Integer size);

	@Query(value = "select * from ExamInfo where name like ? limit ?, ?", nativeQuery = true)
	List<ExamInfo> findPageLike(String name, Integer offset, Integer size);

	@Query(value = "select count(*) from ExamInfo where name = ?", nativeQuery = true)
	Long count(String name);

	@Query(value = "select count(*) from ExamInfo where name like ?", nativeQuery = true)
	Long countLike(String name);
	
	@Query("from ExamInfo order by id asc")
	List<ExamInfo> findAllAsc();

	@Query("select testPaper from ExamInfo where id = ?1")
	TestPaper findTestPaperByExamInfoId(Integer examInfoId);

	List<ExamInfo> findExamInfosByTestPaper_Id(Integer testPaperId);
}

